package de.mhu.mandalaui.widgets;

import de.mhu.mandalaui.Component;
import de.mhu.mandalaui.Response;
import de.mhu.mandalaui.TextComposit;
import de.mhu.mandalaui.text.Text;

public class Button extends Component {

	private TextComposit label;
	
	public Button() {
		setEmphasisStyle(EMPHASIS.DEFAULT);
	}
	
	public Button(String caption) {
		setEmphasisStyle(EMPHASIS.DEFAULT);
		setCaption(caption);
	}

	@Override
	protected void doInitialize() {
		
	}

	@Override
	protected void doDestroy() {
		
	}

	@Override
	public void render(Response response) {
		response.startTag("button", "btn", this);
		if (getLabel() != null) {
			response.containerEnter(getLabel());
			getLabel().render(response);
			response.containerLeave();
		}
		response.endTag("button");
	}

	public TextComposit getLabel() {
		return label;
	}

	public void setLabel(TextComposit label) {
		if (this.label != null) this.label.componentDetach();
		this.label = label;
		if (this.label != null) this.label.componentAttach(this);
	}
	
	public Text setCaption(String text) {
		if (this.label == null) setLabel(new TextComposit());
		this.label.removeAll();
		Text t = new Text(text);
		this.label.add(t);
		return t;
	}

	public String getStyleBase() {
		return "btn";
	}

}
